--require('view')
--require('world')


--[[

	Event Functionality
	
--]]
--Parses all key inputs and calls appropriate function
function parseInput()
	--Get Input
    if love.keyboard.isDown( "up" ) then
        up()
    end
    if love.keyboard.isDown( "down" ) then
        down()
    end
    if love.keyboard.isDown( "left" ) then
        left()
    end
    if love.keyboard.isDown( "right" ) then
        right()
    end

    --Check view boundaries
    if (view:getViewCenter())[0] < ((view:getViewWidth())/2) then
        view:setViewCenter({(view:getViewWidth())/2, (view:getViewCenter())[1]})
    end
    if (view:getViewCenter())[1] < ((view:getViewHeight())/2) then
        view:setViewCenter({(view:getViewCenter())[0], (view:getViewHeight())/2}
    end 
    if (view:getViewCenter())[0] > ((world:getMaxX) - (view:getViewWidth()/2)) then
        view:setViewCenter({((world:getMaxX) - (view:getViewWidth()/2)), (view:getViewCenter())[1]})
    end
    if (view:getViewCenter())[1] > ((world:getMaxY) - (view:getViewHeight()/2)) then
        view:setViewCenter({(view:getViewCenter())[0], ((world:getMaxY) - (view:getViewHeight()/2))})
    end
end

--Parse Up Key
function up()
	player:setYPos(player:getYPos-4)
	view:setTopLeft({view:getTopLeft[0], view:getTopLeft[1]-4})
	view:setTopRight({view:getTopRight[0], view:getTopRight[1]-4})
	view:setBotLeft({view:getBotLeft[0], view:getBotLeft[1]-4})
	view:setBotRight({view:getBotRight[0], view:getBotRight[1]-4})
	view:setViewCenter({view:getViewCenter[0], view:getViewCenter[1]-4})
end

--Parse Down Key
function down()
	player:setYPos(player:getYPos+4)
	view:setTopLeft({view:getTopLeft[0], view:getTopLeft[1]+4})
	view:setTopRight({view:getTopRight[0], view:getTopRight[1]+4})
	view:setBotLeft({view:getBotLeft[0], view:getBotLeft[1]+4})
	view:setBotRight({view:getBotRight[0], view:getBotRight[1]+4})
	view:setViewCenter({view:getViewCenter[0], view:getViewCenter[1]+4})
end

--Parse Left Key
function left()
	player:setXPos(player:getXPos-4)
	view:setTopLeft({view:getTopLeft[0]-4, view:getTopLeft[1]})
	view:setTopRight({view:getTopRight[0]-4, view:getTopRight[1]})
	view:setBotLeft({view:getBotLeft[0]-4, view:getBotLeft[1]})
	view:setBotRight({view:getBotRight[0]-4, view:getBotRight[1]})
	view:setViewCenter({view:getViewCenter[0]-4, view:getViewCenter[1]})
end

--Parse Right Key
function right()
	player:setXPos(player:getXPos+4)
	view:setTopLeft({view:getTopLeft[0]+4, view:getTopLeft[1]})
	view:setTopRight({view:getTopRight[0]+4, view:getTopRight[1]})
	view:setBotLeft({view:getBotLeft[0]+4, view:getBotLeft[1]})
	view:setBotRight({view:getBotRight[0]+4, view:getBotRight[1]})
	view:setViewCenter({view:getViewCenter[0]+4, view:getViewCenter[1]})
end